﻿using CHSystemApi.Framework.DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace CHSystemApi.DataAccess
{
    public static class Services
    {
        public static IServiceCollection AddDatabaseContext(this IServiceCollection services, string connectionstring)
        {
            return services.AddDbContext<DataContext>(option =>
            {
                //MySql
                option.UseMySql(connectionstring, ServerVersion.AutoDetect(connectionstring), x => x.MigrationsAssembly("CHSystemApi.Base"));
                //SqlServer
                //option.UseSqlServer(connectionstring);
            })
            .AddScoped<IDataAccess, DataContext>();
        }
    }
}
